/**
 *
 * $Id: ImageTypes.i,v 1.1 2009-06-07 22:14:56 ttaipalu Exp $
 *
 * \file
 * \brief python wrap for MaCI - Image interface type definitions
 * \author Antti Maula <antti.maula@tkk.fi>
 * \author Tapio Taipalus <tapio.taipalus@tkk.fi>
 */

%{
#include <inttypes.h>
#include <string.h>
#include <string>
#include "owndebug.h"
#include "ImageTypes.hpp"
%}
%include "inttypes.i"
%include "std_string.i"

namespace MaCI {
  
  /** MaCI - Image Interface
   *
   * This namespace contains all the methods and types related to
   * the MaCI - Image Interface
   *
   */
  namespace Image {
    

    /**
     * Type identifiers inside BinBag frame. Used for dynamic encoding/decoding
     * of message frames
     *
     */
    enum EImageElementType { 
      KTypeUnknown       = -1,  ///< Unknown type
      KTypeTimestamp     = 1,   ///< Contains a timestamp (TTimestamp)
      KTypeImageInfo     = 3,   ///< Image information.
      KTypeImageData     = 4,   ///< Contains Imagedata. (raw - uncompress/use directly)
      KTypeCommand       = 5,   ///< Contains a command (TCommand)
      KTypeSourceInfo    = 6    ///< SourceInfo (TSourceInfo)
    };
    

    /** 
     * Currently defined image formats. This enum is used inside
     * TImageInfo container.
     */
    enum EImageDataType { 
      KImageDataUnknown   = 0, ///< Unknown (not set) type.
      KImageDataJPEG      = 1, ///< JPEG image (packed)
      KImageDataPNG       = 2, ///< PNG image (packed)
      KImageDataRGB       = 3, ///< RGB Image ([Red,Green,Blue]; 1 byte per color)
      KImageDataYUV420P   = 4, ///< YUV420P image
      KImageDataYUV422    = 5, ///< YUV422 image
      KImageDataGreyscale = 6, ///< Greyscale image ([brightness], 1 byte per pixel)
      KImageDataRaw       = 7,  ///< Raw imageformat. (Unknown to Interface, Avoid this!)
      KImageDataRGBA      = 8  //7< RGBA. [Red,Green,Blue,Alpha]; 1 byte per color/alpha
    };


    /** 
     * Commands available (Commands are paired with appropriate following dataelements)
     */
    enum EImageCommand { 
      KCommandUnknown                = -1, ///< Unknown type
      KCommandNewImage               = 1,  ///< Get new image. 
      KCommandGetSourceInfoArray     = 2,  ///< Get SourceInfo array. (All SourceInfos)
      KCommandSetSourceInfoArray     = 3   ///< Set SourceInfo. Normally sent to client.
    };
    
    
    /**
     * Describes Commands for Image interface
     *
     */
    struct TCommand {
      TCommand(EImageCommand aCmd = KCommandUnknown) 
	: cmd(aCmd) {}
      
      uint32_t cmd; ///< Command \see EImageCommand
    };


    /**
     * Image Information field.
     */
    struct TImageInfo {
      TImageInfo(const unsigned int aWidth = 0,
                 const unsigned int aHeight = 0,
                 const MaCI::Image::EImageDataType aImageDataType = MaCI::Image::KImageDataUnknown,
                 const uint8_t aSourceIndex = 0)
        : imagewidth(aWidth),
          imageheight(aHeight),
          imagedatatype(aImageDataType),
          sourceindex(aSourceIndex),
          reserved(0) {
      }
      
      /** Debug print function.
       */
      void Print(int lvl) const {
        dPrint(lvl,"\tSource:\t'%u'", sourceindex);
        dPrint(lvl,"\timagewidth:\t%u", imagewidth);
        dPrint(lvl,"\timageheight:\t%u", imageheight);
        dPrint(lvl,"\timagedatatype:\t%u", imagedatatype);
      }
      
      uint16_t imagewidth;   ///< Image width (in pixels)
      uint16_t imageheight;  ///< Image height (in pixels)
      uint8_t imagedatatype; ///< Datatype of following dataelement. (see EImageDataType)
      uint8_t sourceindex;   ///< Source index. Is identified by TInterfaceInfo
      uint8_t reserved;      ///< Unused field, reserved for future use.
    };
    
    
    
    /** Describes single source.
     */
    struct TSourceInfo {
      TSourceInfo(const uint8_t aIndex = 0,
                  const std::string &aName = "Unknown",
                  const std::string &aDescr = "Unknown imagesource")
        : sourceindex(aIndex),
          sourcename(),
          sourcedescription() {
        // Take the name & truncate if required.
        strncpy(sourcename, aName.c_str(),sizeof(sourcename));
        sourcename[sizeof(sourcename)-1] = 0;
        
        // Take the description & truncate if required.
        strncpy(sourcedescription, aDescr.c_str(), sizeof(sourcedescription));
        sourcedescription[sizeof(sourcedescription)-1] = 0;
      }
      
      uint8_t sourceindex;         ///< Source name index (matches integer in imagestream)
      char sourcename[31];         ///< Source short name, could be machine processable.
      char sourcedescription[256]; ///< Description of source. 
    };

  }
}


